﻿using UnityEngine;
using UnityEditor;
using UnityEngine.Rendering;

namespace CustomSR
{
    [CanEditMultipleObjects]
    [CustomEditorForRenderPipeline(typeof(Light), typeof(CustomRendePineAsset))]
    public class CustomLightEditor : LightEditor 
    {
        static GUIContent renderingLayerMaskLabel = new GUIContent("Custom Rendering Layer Mask", "Functional version of above property.");
        //void DrawRenderingLayerMask()
        //{
        //    SerializedProperty property = settings.renderingLayerMask;
        //    EditorGUI.showMixedValue = property.hasMultipleDifferentValues;
        //    EditorGUI.BeginChangeCheck();
        //    int mask = property.intValue;
        //    if (mask == int.MaxValue) {
        //        mask = -1;
        //    }
        //    mask = EditorGUILayout.MaskField( renderingLayerMaskLabel, mask,GraphicsSettings.currentRenderPipeline.renderingLayerMaskNames);
        //    if (EditorGUI.EndChangeCheck())
        //    {
        //        property.intValue = mask == -1 ? int.MaxValue : mask;
        //    }
        //    EditorGUI.showMixedValue = false;
        //}

        public override void OnInspectorGUI()
        {
            base.OnInspectorGUI();

            //DrawRenderingLayerMask();
            RenderingLayerMaskDrawer.Draw(settings.renderingLayerMask, renderingLayerMaskLabel);

            if ( !settings.lightType.hasMultipleDifferentValues && (LightType)settings.lightType.enumValueIndex == LightType.Spot)
            {
                settings.DrawInnerAndOuterSpotAngle();
           
            }

            settings.ApplyModifiedProperties();

            var light = target as Light;
            if (light.cullingMask != -1)
            {
                EditorGUILayout.HelpBox(
                     light.type == LightType.Directional ?
                         "Culling Mask only affects shadows." :
                         "Culling Mask only affects shadow unless Use Lights Per Objects is on.",
                     MessageType.Warning
                 );
            }
        }
    }
}